package com.blacktech.dbu.meta.entity;

import com.blacktech.dbu.core.annotation.Searchable;
import com.blacktech.dbu.core.common.BaseEntity;
import com.blacktech.dbu.core.dict.DatabaseDialect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;

/**
 * 数据库模式信息
 *
 * @author yanyunsong
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "dbu_schema")
public class DbuSchema extends BaseEntity {
    /**
     * 数据库模式名称
     */
    @Searchable(value = "模式名称", priority = 1)
    @Column(name = "schema_name")
    private String schemaName;

    /**
     * 数据库类型
     */
    @Column(name = "db_type")
    @Enumerated(EnumType.STRING)
    private DatabaseDialect dbType;

    /**
     * 连接信息
     */
    @Column(name = "connection_info", length = 1000)
    private String connectionInfo;

    /**
     * 描述
     */
    @Searchable(value = "模式描述", priority = 2)
    @Column(name = "description", length = 500)
    private String description;

    /**
     * 关联的产品
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id")
    @JsonIgnore
    private DbuProduct product;

    /**
     * 模式下的数据表列表
     */
    @OneToMany(mappedBy = "schema", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JsonIgnore
    private List<DbuTable> tables;
}